package com.hotel.factory;

import com.hotel.service.Impl.FoodTypeServiceImpl;

import java.util.ResourceBundle;

/**
 * 工厂：创建dao或service实例
 * Created by LinYaTing on 2018/11/24 12:06
 */
public class BeanFactory {

    //加载配置文件
    private static ResourceBundle bundle;
    static {
        bundle = ResourceBundle.getBundle("instance");
    }

    /**
     * 根据指定的key，读取配置文件获取类的全路径：创建对象
     */
    public static <T> T getInstance(String key, Class<T> clazz) {
        //根据指定的key，读取配置文件获取类的全路径
        String className = bundle.getString(key);
        //创建对象
        try {
            return (T) Class.forName(className).newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
